package com.xk.utils;


import org.springframework.util.StringUtils;

import java.lang.reflect.Field;

/**
 * 实体类属性校验工具类
 */
public class EntityUtils {

    /**
     * 判断实体类所有属性不能为空
     *
     * @param obj 实体类对象
     */
  /*  public static void checkAllFieldNotNull(Object obj) {
        Field[] fields = obj.getClass().getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            Object value;
            try {
                value = field.get(obj);
            } catch (IllegalAccessException e) {
                throw new SystemException(AppHttpCodeEnum.SYSTEM_ERROR);
            }
            if (value == null) {
                throw new SystemException(AppHttpCodeEnum.REQUEST_ILLEGAL);
            }
        }
    }*/

    /**
     * 判断实体类指定属性不能为空
     *
     * @param obj       实体类对象
     * @param fieldName 属性名称
     */
   /* public static void checkFieldNotNull(Object obj, String fieldName) {
        Field field;
        try {
            field = obj.getClass().getDeclaredField(fieldName);
        } catch (NoSuchFieldException e) {
            throw new SystemException(AppHttpCodeEnum.SYSTEM_ERROR);
        }
        field.setAccessible(true);
        Object value;
        try {
            value = field.get(obj);
        } catch (IllegalAccessException e) {
            throw new SystemException(AppHttpCodeEnum.SYSTEM_ERROR);
        }
        if (value == null) {
            throw new SystemException(AppHttpCodeEnum.REQUEST_ILLEGAL);
        }
    }*/

    /**
     * 判断字符串是否为空
     *
     * @param str 字符串
     */
    public static boolean isNullOrEmpty(String str) {
        return StringUtils.isEmpty(str) || !StringUtils.hasText(str);
    }


}


